<template>
    <div class="app-container">
        <el-card class="filter-container" shadow="never">
            <div>
                <i class="el-icon-search"></i>
                <span>筛选搜索</span>
                <el-button style="float:right" type="primary" @click="handleSearchList()" size="small">查询搜索</el-button>
                <el-button
                        style="float:right;margin-right: 15px"
                        @click="handleResetSearch()"
                        size="small"
                >重置</el-button>
            </div>
            <div style="margin-top: 15px">
                <el-form :inline="true" :model="listQuery" size="small" label-width="140px">
                    <el-form-item label="用户手机:">
                        <el-input v-model="listQuery.memberPhone" class="input-width" placeholder="用户手机"></el-input>
                    </el-form-item>
                    <el-form-item label="核销券码:">
                        <el-input v-model="listQuery.code" class="input-width" placeholder="核销券码"></el-input>
                    </el-form-item>
                    <el-form-item label="开始日期：">
                    <el-date-picker
                    class="input-width"
                    v-model="listQuery.startTime"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="请选择时间"
                    ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束日期：">
                    <el-date-picker
                    class="input-width"
                    v-model="listQuery.endTime"
                    value-format="yyyy-MM-dd"
                    type="date"
                    placeholder="请选择时间"
                    ></el-date-picker>
                    </el-form-item>
                </el-form>
            </div>
        </el-card>
        <el-card class="operate-container" shadow="never">
            <i class="el-icon-tickets"></i>
            <span>数据列表</span>
        </el-card>
        <div class="table-container">
            <el-table
                    ref="deviceTable"
                    :data="list"
                    style="width: 100%;"
                    @selection-change="handleSelectionChange"
                    v-loading="listLoading"
                    border
            >
                <el-table-column type="selection" width="60" align="center"></el-table-column>
                <el-table-column label="编号" width="120" align="center">
                    <template slot-scope="scope">{{scope.row.id}}</template>
                </el-table-column>
                <el-table-column label="核销平台" width="150" align="center">
                    <template slot-scope="scope">{{scope.row.hexiaoType | typeFilter}}</template>
                </el-table-column>
                <el-table-column label="核销券码" width="250" align="center">
                    <template slot-scope="scope">{{scope.row.code}}</template>
                </el-table-column>
                <el-table-column label="核销用户" width="200" align="center">
                    <template slot-scope="scope">{{scope.row.memberName}}</template>
                </el-table-column>
                <el-table-column label="用户手机号" width="250" align="center">
                    <template slot-scope="scope">{{scope.row.memberPhone}}</template>
                </el-table-column>
                <el-table-column label="核销时间" width="250" align="center">
                    <template slot-scope="scope">{{scope.row.createDatetime | formatTime}}</template>
                </el-table-column>
                <el-table-column label="核销积分" width="250" align="center">
                    <template slot-scope="scope">{{scope.row.integral}}</template>
                </el-table-column>
            </el-table>
        </div>
        <div class="pagination-container">
            <el-pagination
                    background
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
                    layout="total, sizes,prev, pager, next,jumper"
                    :page-size="listQuery.pageSize"
                    :page-sizes="[5,10,15]"
                    :current-page.sync="listQuery.pageNum"
                    :total="total"
            ></el-pagination>
        </div>
    </div>
</template>
<script>
    import {fetchList, deleteRoom} from "@/api/qsg/hexiao";
    import {formatDate} from "@/utils/date";

    const defaultListQuery = {
        pageNum: 1,
        pageSize: 100
    };
    export default {
        name: "deviceList",
        data() {
            return {
                listQuery: Object.assign({}, defaultListQuery),
                list: null,
                total: null,
                listLoading: false,
                multipleSelection: []
            };
        },
        created() {
            this.getList();
        },
        filters: {
            formatTime(time) {
                if (time == null || time === "") {
                    return "N/A";
                }
                let date = new Date(time);
                return formatDate(date, "yyyy-MM-dd hh:mm:ss");
            },
            typeFilter(status) {
                if (status == 0) {
                    return '抖音'
                } else {
                    return '美团'
                }
            }
        },
        methods: {
            handleResetSearch() {
                this.listQuery = Object.assign({}, defaultListQuery);
            },
            handleSearchList() {
                this.listQuery.pageNum = 1;
                this.getList();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handleSizeChange(val) {
                this.listQuery.pageNum = 1;
                this.listQuery.pageSize = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.listQuery.pageNum = val;
                this.getList();
            },
            getList() {
                this.listLoading = true;
                fetchList(this.listQuery).then(response => {
                    this.listLoading = false;
                    this.list = response.data.records;
                    this.total = response.data.total;
                });
            }
        }
    };
</script>
<style scoped>
    .input-width {
        width: 203px;
    }
</style>


